package com.chen.my_leet._2023_11;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @Author: ChromeChen
 * @Description: 反转数组：https://leetcode.cn/problems/rotate-array/
 * @Date: Created in 17:19 2023/11/6
 * @Modified By:
 */
public class Leet189 {

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6, 7};
        rotateV1(nums, 3);
        // rotate(nums, 3);
    }

    /**
     * 第一种反转：循环方法
     * @param nums
     * @param k
     */
    private  static void rotateV1(int[] nums, int k) {
        int max_gongyue = max_gongyue(nums.length, k);
        int min_gongbei = nums.length * k / max_gongyue;

        int jupmpCount = min_gongbei / k;


        for (int j = 0; j < k; j++) {
            int start = j;
            int temp = nums[start];
            for (int i = 0; i < jupmpCount; i++) {
                int end = (start + k) % nums.length;

                int new_temp = nums[end];
                nums[end] = temp;
                temp = new_temp;

                start = end;
            }
        }


        Arrays.stream(nums).forEach(System.out::print);

    }

    private static int max_gongyue(int n, int k) {
        if (n % k == 0) {
            return k;
        }
        return max_gongyue(k, n % k);
    }
}
